package com.literaryfamily.literaryfamily.enumPackage;

import com.literaryfamily.literaryfamily.exceptions.OperationException;

public enum PaymentMethod {
	WECHAT(0, "微信"),
	ALIPAY(1, "支付宝"),
	BANKCARD(2, "银行卡"),
	OFFLINE(3, "线下交易"),
	ELSE_METHOD(4, "其他");

	private final int methodNum;
	private final String methodName;

	private PaymentMethod(int methodNum, String methodName) {
		this.methodNum = methodNum;
		this.methodName = methodName;
	}

	public int getMethodNum() {
		return methodNum;
	}

	public String getMethodName() {
		return methodName;
	}

	public static PaymentMethod getPaymentMethod(Integer methodNum) {
		if (methodNum == null) throw new OperationException("不存在的支付方式");
		for (PaymentMethod paymentMethod : PaymentMethod.values()) {
			if (paymentMethod.getMethodNum() == methodNum) {
				return paymentMethod;
			}
		}
		throw new OperationException("不存在的支付方式");
	}
}